package com.hontech.bv.ui.fragment.arm

import android.view.View
import com.hontech.bv.R
import com.hontech.bv.model.arm.ArmStatus
import com.hontech.bv.ui.view.NumberSensorView
import com.hontech.bv.ui.view.SwitchSensorView

class StatusDelegate (view: View) {

    private val jawOpen = view.findViewById<SwitchSensorView>(R.id.id_arm_sw_jaw_open)
    private val jawClose = view.findViewById<SwitchSensorView>(R.id.id_arm_sw_jaw_close)
    private val filmDrop = view.findViewById<SwitchSensorView>(R.id.id_arm_film_drop)
    private val filmCargo = view.findViewById<SwitchSensorView>(R.id.id_arm_film_cargo)
    private val stepZero = view.findViewById<SwitchSensorView>(R.id.id_arm_step_zero)
    private val stepAlm = view.findViewById<SwitchSensorView>(R.id.id_arm_step_alm)

    private val nswP1 = view.findViewById<NumberSensorView>(R.id.id_arm_nsw_p1)
    private val nswP2 = view.findViewById<NumberSensorView>(R.id.id_arm_nsw_p2)

    fun update() {
        val sw = ArmStatus.switchValue()

        jawOpen.set(sw.isJawOpen)
        jawClose.set(sw.jsJawClose)
        filmDrop.set(sw.isFilmDrop)
        filmCargo.set(sw.isFilmCargo)
        stepZero.set(sw.isStepZero)
        stepAlm.set(sw.isStepAlm)

        nswP1.set(ArmStatus.status.p1.signalValue())
        nswP2.set(ArmStatus.status.p2.signalValue())
    }
}

